﻿using System;
using UnityEngine;

// Token: 0x0200037D RID: 893
public class NormalLerpManager
{
	// Token: 0x06001633 RID: 5683 RVA: 0x0009469C File Offset: 0x0009289C
	public NormalLerpManager(Transform root, NormalData targetData)
	{
		this.root = root;
		this.targetData = targetData;
		if (targetData == null)
		{
			return;
		}
		this.meshs = new Mesh[targetData.data.Count];
		for (int i = 0; i < targetData.data.Count; i++)
		{
			Renderer renderer = Transform_Utility.FindComponent<Renderer>(root.gameObject, targetData.data[i].ObjectName);
			if (renderer != null)
			{
				Mesh mesh = NormalLerpManager.CloneMesh(renderer.gameObject);
				if (mesh.normals.Length == targetData.data[i].NormalMin.Count)
				{
					this.meshs[i] = mesh;
				}
				else
				{
					GlobalData.Debug_LogError(string.Concat(new object[]
					{
						"网格的法线数不一致：",
						targetData.data[i].ObjectName,
						" ",
						mesh.normals.Length,
						",",
						targetData.data[i].NormalMin.Count
					}));
				}
			}
			else
			{
				GlobalData.Debug_LogError("没有网格：" + targetData.data[i].ObjectName);
			}
		}
	}

	// Token: 0x06001634 RID: 5684 RVA: 0x000947F4 File Offset: 0x000929F4
	public static Mesh CloneMesh(GameObject OriginalData)
	{
		MeshFilter meshFilter = OriginalData.GetComponent(typeof(MeshFilter)) as MeshFilter;
		if (null != meshFilter)
		{
			Mesh mesh = UnityEngine.Object.Instantiate<Mesh>(meshFilter.sharedMesh);
			mesh.name = meshFilter.sharedMesh.name;
			meshFilter.sharedMesh = mesh;
			return meshFilter.sharedMesh;
		}
		SkinnedMeshRenderer component = OriginalData.GetComponent<SkinnedMeshRenderer>();
		if (component && component.sharedMesh)
		{
			Mesh mesh2 = UnityEngine.Object.Instantiate<Mesh>(component.sharedMesh);
			mesh2.name = component.sharedMesh.name;
			component.sharedMesh = mesh2;
			return component.sharedMesh;
		}
		return null;
	}

	// Token: 0x06001635 RID: 5685 RVA: 0x0009489C File Offset: 0x00092A9C
	public void Lerp(float rate)
	{
		if (this.targetData == null)
		{
			return;
		}
		for (int i = 0; i < this.meshs.Length; i++)
		{
			if (!(this.meshs[i] == null))
			{
				NormalData.Param param = this.targetData.data[i];
				Vector3[] array = new Vector3[param.NormalMin.Count];
				for (int j = 0; j < array.Length; j++)
				{
					array[j] = Vector3.Lerp(param.NormalMin[j], param.NormalMax[j], rate);
				}
				this.meshs[i].normals = array;
			}
		}
	}

	// Token: 0x040019E9 RID: 6633
	private Transform root;

	// Token: 0x040019EA RID: 6634
	private NormalData targetData;

	// Token: 0x040019EB RID: 6635
	private Mesh[] meshs;
}
